package handlers

import (
	"context"
	"github.com/gin-gonic/gin"
	log "github.com/sirupsen/logrus"
	"github.com/twwch/gin-sdk/handler"
	"github.com/twwch/gin-sdk/server"
	"net/http"
	namespaceSvc "twwch/k8s-admin/application/namespace"
	"twwch/k8s-admin/models/common"
	"twwch/k8s-admin/models/namespace"
)

type NamespaceHandler struct {
	handler.Base
	namespaceSvc *namespaceSvc.NamespaceService
}

func (h *NamespaceHandler) Init(ginRouter *gin.RouterGroup) {
	h.Logger = log.WithField("handler", "namespace")
	h.namespaceSvc = namespaceSvc.GetService()
	// registry http handler
	if ginRouter != nil {
		appGroup := ginRouter.Group("/namespace")
		server.Route(appGroup, http.MethodGet, "/list", h.List)
		server.Route(appGroup, http.MethodGet, "/delete", h.Delete)
		//appGroup.GET("/", warper.CreateHandlerFunc(h.Test, false))
	}
}

func (h *NamespaceHandler) List(ctx context.Context, req *namespace.ListReq) (*namespace.ListResp, error) {
	return h.namespaceSvc.ListNamespace(ctx, req)
}

func (h *NamespaceHandler) Delete(ctx context.Context, req *namespace.DeleteReq) (*common.Empty, error) {
	return h.namespaceSvc.DeleteNamespace(ctx, req)
}
